package com.optimus.common.util;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 *
 * @author victor
 */
public class Convertidor {
    private static  Logger logger = LoggerFactory.getLogger(Convertidor.class);
    public static String getString(Object object, String def, Long ticket){
        if (object instanceof String){
            return (String) object;
        }
        logger.debug("Retornando valor por defecto ");
        return def;
    }
    public static Date getDate(Object object, Date def, Long ticket){
        if (object instanceof Date){
            return (Date) object;
        }
        logger.debug("Retornando valor por defecto ");
        return def;
    }
    public static Integer getInteger(Object object, Integer def, Long ticket){
        if (object instanceof Integer){
            return (Integer) object;
        }
        logger.debug("Retornando valor por defecto ");
        return def;
    }
    public static Integer getString2Integer(Object object, Integer def, Long ticket){
        if (object instanceof String){
            return Integer.valueOf((String)object);
        }
        logger.debug("Retornando valor por defecto ");
        return def;
    }
    public static Float getFloat(Object object, Float def, Long ticket){
        if (object instanceof Float){
            return (Float) object;
        }
        logger.debug("Retornando valor por defecto ");
        return def;
    }
    public static BigDecimal getBigDecimal(Object object, BigDecimal def, Long ticket){
        if (object instanceof BigDecimal){
            return (BigDecimal) object;
        }
        logger.debug("Retornando valor por defecto ");
        return def;
    }
    public static Date getString2Date(String dateStr,String format, Date def, Long ticket){
        try {
            SimpleDateFormat sdf = null;
            if(format !=null|| "".equals(format) ){
                sdf=new SimpleDateFormat(format);
            }else{
                sdf = new  SimpleDateFormat("dd/MM/yyyy");
            }
            return sdf.parse(dateStr);
        } catch (ParseException ex) {
            logger.error("Retornando valor por defecto ");
        }
        logger.debug("Retornando valor por defecto ");
        return def;
    }
    
}
